﻿@model ProductSummaryModel.SummaryItem

@using SmartStore.Web.Models.Catalog;
@using SmartStore.Core.Domain.Orders;

@{ 
	var list = Model.Parent;
	var price = Model.Price;
	var artDetailUrl = Url.RouteUrl("Product", new RouteValueDictionary { { "SeName", Model.SeName } });
}

@helper RenderBuyButton(bool blockStyle) {{
	var cssClasses = blockStyle ? "btn-block d-none d-md-block" : "x-btn-icon btn-lg art-btn col";
	if (!blockStyle && Model.Parent.ViewMode == ProductSummaryViewMode.List)
	{
		cssClasses += " d-md-none";
	}
	if (!Model.Price.CallForPrice)
	{
		var addToCartUrl = Url.Action("AddProductSimple", "ShoppingCart", new { productId = Model.Id, forceredirection = Model.Parent.ForceRedirectionAfterAddingToCart, area = "" });
		var title = (Model.Price.AvailableForPreOrder ? T("ShoppingCart.PreOrder") : T("ShoppingCart.AddToCart"));

		<a data-href='@addToCartUrl'
			href="#"
			class="btn btn-primary ajax-cart-link @cssClasses"
			title="@title"
			data-toggle='@(!blockStyle ? "tooltip" : "")' data-placement="bottom"
			rel="nofollow"
			data-type="cart"
			data-action="add">
			<i class="fa fa-cart-arrow-down"></i>
			@if (blockStyle)
			{
				<span>@title</span>
			}
			else if (Model.Parent.ViewMode == ProductSummaryViewMode.List)
			{
				<span class="d-none d-sm-inline">@title</span>
			}
		</a>
	}
	else
	{
		<a href="@Url.Action("AskQuestion", "Product", new RouteValueDictionary { { "id", Model.Id }, { "area", "" } })"
			class="btn @(blockStyle ? "btn-secondary" : "btn-gray") add-to-cart-button @cssClasses"
			data-toggle='@(!blockStyle ? "tooltip" : "")' data-placement="bottom"
			rel="nofollow"
			title="@T("Products.CallForPrice.GoToForm")">
			<i class="fa fa-envelope"></i>
			@if (blockStyle)
			{
				<span>@T("Products.CallForPrice.GoToForm")</span>
			}
			else if (Model.Parent.ViewMode == ProductSummaryViewMode.List)
			{
				@* Show "Call for price" label on sm-only (enough space!) *@
				<span class="d-none d-sm-inline">@T("Products.CallForPrice.GoToForm")</span>
			}
		</a>
	}
}}

@if (list.ViewMode == ProductSummaryViewMode.List && !price.DisableBuyButton && list.BuyEnabled)
{
	<div class="my-3">
		@RenderBuyButton(true)
	</div>
}

<div class="row no-gutters art-btn-group">
	@if (!price.DisableBuyButton && list.BuyEnabled)
	{
		@RenderBuyButton(false)
	}

	@if (!price.DisableWishlistButton && list.WishlistEnabled)
	{
		<a data-href='@Url.Action("AddProductSimple", "ShoppingCart", new { productId = Model.Id, shoppingCartTypeId = (int)ShoppingCartType.Wishlist , area = "" })'
			href="#"
			class="btn btn-secondary btn-lg art-btn col ajax-cart-link" 
			title="@T("Categories.Wishlist")"
			data-toggle="tooltip" data-placement="bottom"
			rel="nofollow"
			data-type="wishlist" 
			data-action="add">
			<i class="fal fa-heart"></i>
		</a>
	}
	else if (list.ViewMode == ProductSummaryViewMode.List)
	{
		<span class="art-btn-spacer col"></span>
	}

	@if (list.CompareEnabled)
	{
		<a data-href="@Url.Action("AddProductToCompare", "Catalog", new RouteValueDictionary { { "id", Model.Id }, { "area", "" } })" 
			href="#"
			class="btn btn-secondary btn-lg art-btn col ajax-cart-link" 
			title="@T("Categories.Compare")"  
			data-toggle="tooltip" data-placement="bottom" 
			rel="nofollow"
			data-type="compare" 
			data-action="add">
			<i class="fa fa-retweet"></i>
		</a>
	}
	else if (list.ViewMode == ProductSummaryViewMode.List)
	{
		<span class="art-btn-spacer col"></span>
	}

	<a href='@Url.RouteUrl("Product", new RouteValueDictionary { { "SeName", Model.SeName } })' 
		class="btn btn-secondary btn-lg art-btn col" 
		title="@T("Products.Details")">
		<i class="fa fa-info"></i>
	</a>
</div>

